package com.ctgu.project.controller;

import com.ctgu.project.service.ShopsService;
import com.ctgu.project.utils.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName ShopsController
 * @Author Alex2
 * @Date 2025/2/27 9:54
 **/
@RestController
@RequestMapping("/api/shop")
public class ShopsController {

    @Autowired
    private ShopsService shopsService;

    /**
     * @Author: Alex
     * @Description: 像数据库中插入商铺信息
     */
    // http://localhost:8080/api/shop/insertShopInfo
    @GetMapping("/insertShopInfo")
    public ApiResult insertShopInfo() {
        return shopsService.insertShopInfo();
    }

    /**
     * @Author: Alex
     * @Description: 将商铺信息加载到 Redis，根据商铺类型分类
     */
    // http://localhost:8080/api/shop/loadShopData
    @GetMapping("/loadShopData")
    public ApiResult loadShopData() {
        return shopsService.loadShopData();
    }

    /**
     * @Author: Alex
     * @Description: 查询附近商铺的信息
     */
    // http://localhost:8080/api/shop/getShopByType?typeId=1&lng=120.10000&lat=30.30000&distance=10000000
    @GetMapping("/getShopByType")
    public ApiResult getShopByType(
            @RequestParam("typeId") Integer typeId,
            @RequestParam(value = "lng", required = false) Double lng,
            @RequestParam(value = "lat", required = false) Double lat,
            @RequestParam(value = "distance", required = false) Long distance) {
        return shopsService.getShopByType(typeId, lng, lat, distance);
    }
}